package com.gpStudy.thread.gp.condition;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;

public class ConditionWait implements Runnable {

    private Lock lock;
    private Condition condition;

    public ConditionWait(Lock lock, Condition condition) {
        this.lock = lock;
        this.condition = condition;
    }

    public void run() {

        try {
            lock.lock();//竞争锁
            System.out.println("begin - conditionWaite");
            try {
                condition.await(); // 阻塞
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("end - conditionWaite");
        } finally {
            lock.unlock();// 释放锁
        }

    }
}
